package com.example.vae.Home.Invitation.invitation_three;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.vae.Adapter.TieZiRecyclerViewAdapter;
import com.example.vae.GuangchangViewModel;
import com.example.vae.Pojo.TieZi;
import com.example.vae.R;
import com.example.vae.Utils.RandomString;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;


//这里是圈子 fragement 中的 广场一些数据
public class guangchangFragment extends Fragment {

    private GuangchangViewModel mViewModel;
    private RecyclerView recyclerView;
    private TieZiRecyclerViewAdapter adapter;
    private List<TieZi> tieZiList=new ArrayList<>();

    public static guangchangFragment newInstance() {
        return new guangchangFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.guangchang_fragment, container, false);
        recyclerView=view.findViewById(R.id.re);
        initdata();
        adapter=new TieZiRecyclerViewAdapter(getActivity(),tieZiList);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(GuangchangViewModel.class);
        // TODO: Use the ViewModel
    }

//    数据
    private void  initdata(){
        int[] imageRess = new int[]{R.drawable.ic_1,R.drawable.ic_2,R.drawable.ic_3,R.drawable.ic_4,R.drawable.dongtai_1,R.drawable.dongtai_2,R.drawable.dongtai_3,R.drawable.dongtai_4,R.drawable.find_logo};
        List<Integer> imgs;
        String [] loactions={"南京","北京","上海","深圳"};
        for(int i=0;i<10;i++){
            imgs=new ArrayList<>();
            for(int j=0;j<i;j++){
                imgs.add(imageRess[new Random().nextInt(100)%9]);
            }
            String name = RandomString.getRandomString(4);
            String id= String.valueOf(i);
            int tuxiang=imageRess[new Random().nextInt(10)%9];
            String context=RandomString.getRandomString(50);
            String location=loactions[new Random().nextInt(100)%4];
            int good=new Random().nextInt(100);
            int mes=new Random().nextInt(1000);
            String date=new Date().toString();
            TieZi tieZi=new TieZi(name,id,tuxiang,context,imgs,location,date,good,mes);
            tieZiList.add(tieZi);
        }
    }
}
